package cn.life.business.home.service.impl;

import cn.life.business.home.service.HomeService;
import cn.life.business.material.dao.MaterialDao;
import cn.life.business.material.entity.vo.MaterialRecVo;
import cn.life.business.notice.dao.NoticeDao;
import cn.life.business.notice.entity.vo.NoticeVo;
import cn.life.business.schedule.dao.ScheduleDao;
import cn.life.business.schedule.entity.po.Schedule;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUserInfo;
import cn.life.common.entity.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author 李佳明
 * @Date 2018/11/29 0029.21:52.
 */
@Service
@Transactional
public class HomeServiceImpl implements HomeService{

    @Autowired
    private MaterialDao materialDao;

    @Autowired
    private ScheduleDao scheduleDao;

    @Autowired
    private NoticeDao noticeDao;

    @Override
    public CMessage queryHomeMenu(MyUserInfo myUserInfo) {
        Map<String,Integer> map = new HashMap<String,Integer>();
        map.put("schedule",0);
        map.put("material",0);
        //1.提料单
        List<MaterialRecVo> materialRecs = materialDao.queryMaterialRecList("",myUserInfo.getProjectId(),myUserInfo.getUserId());
        for(MaterialRecVo materialRecVo : materialRecs){
            if(materialRecVo.getIsMyAudit() == 1){
                map.put("material",1);
                break;
            }
        }
        //2.进度
        List<Schedule> schedules = scheduleDao.queryLastRecordList(myUserInfo.getUserId(),"",myUserInfo.getProjectId(),null,null);
        for(Schedule schedule : schedules){
            if(schedule.getAuditState() != 0 && schedule.getIsMyAudit() == 1){
                map.put("schedule",1);
                break;
            }
        }
        //3.公告
        Integer notReadNumber = noticeDao.queryMyNotReadNumber(myUserInfo.getProjectId(),myUserInfo.getUserId());
        map.put("notice",notReadNumber);
        return CMessage.successByData(map);
    }
}
